{include file="header.htm" /}
<link href="__SKIN__/css/main.css?v={$version}" rel="stylesheet" type="text/css">
<link href="__SKIN__/css/page.css?v={$version}" rel="stylesheet" type="text/css">
<body class="bodystyle" style="cursor: default; -moz-user-select: inherit; min-width:400px;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<style type="text/css">
    .layui-layer-btn .layui-layer-btn0 {border-color: #4fc0e8; background-color: #4fc0e8}
</style>
<div class="page" style="min-width: 400px;">
    {empty name="$dealer_id"}{include file="bar.htm" /}{/empty}
    <div class="flexigrid flexigrid-xin">
        <div class="header-bar">
            <div class="more">
                <div class="search">
                    <div class="content">
                        <form id="searchForm" action="{:weapp_url('DealerPlugin/DealerPlugin/dealer_withdraw')}" method="get" onsubmit="layer_loading('正在处理');" style="display: unset;">
                            {$searchform.hidden|default=''}
                            <input type="hidden" name="dealer_id" value="{$Request.param.dealer_id}">
                            <div class="ey-form-item"><label class="users-form-item-label">关键词：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <!-- 订单号查询 -->
                                            <div class="sDiv2">
                                                <input type="text" size="50" name="keywords" id="keywords" value="{$Request.param.keywords}" class="qsbox" style="width: 170px;" placeholder="搜索分销商/手机号...">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="ey-form-item"><label class="users-form-item-label">提现状态：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="">
                                                <select name="review_status" id="review_status">
                                                    <option value="" >全部</option>
                                                    <option value="1" {eq name="$Request.param.review_status" value="1"}selected{/eq}>待审核</option>
                                                    <option value="2" {eq name="$Request.param.review_status" value="2"}selected{/eq}>待打款</option>
                                                    <option value="4" {eq name="$Request.param.review_status" value="4"}selected{/eq}>已打款</option>
                                                    <option value="3" {eq name="$Request.param.review_status" value="3"}selected{/eq}>已拒绝</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="ey-form-item"><label class="users-form-item-label">申请时间：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" name="add_time_begin" id="add_time_begin" autocomplete="off" value="{$Request.param.add_time_begin}" class="qsbox" placeholder="起始日期">
                                            </div>
                                            &nbsp;至&nbsp;
                                            <div class="sDiv2">
                                                <input type="text" name="add_time_end" id="add_time_end" autocomplete="off" value="{$Request.param.add_time_end}" class="qsbox" placeholder="结束日期">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <div class="ey-form-item" style="margin-left: 20px;">
                            <div class="users-form-item-content">
                                <span class="bt-xin" onclick="withdrawQuery();">查询</span>
                                <span class="bt-xin-no" onclick="withdrawQuery(this);" data-url="{:weapp_url('DealerPlugin/DealerPlugin/dealer_withdraw', ['dealer_id'=>$dealer_id])}">重置</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="flexigrid member_lt" style="padding-top: 20px;">
        {empty name="withdrawList"}
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%;">
                    <thead>
                        <tr>
                            <!-- <th axis="col4"> <div class="tl text-l10">会员名/会员昵称</div> </th> -->
                            <th axis="col4"> <div class="tl text-l10">会员昵称</div> </th>
                            <th axis="col4" class="w100"> <div class="tc">分销商级别</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">分销商姓名/手机号</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">提现方式</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">申请佣金</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">申请时间</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">状态</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">操作</div> </th>
                        </tr>
                    </thead>
                    <tbody>
                        
                    </tbody>
                </table>
                <div class="no_row" style="background: #FFF;">
                    <div class="no_pic" style=" width: auto; line-height: 350px !important; height: 380px; text-align: center; margin: 0 auto; position: unset !important;"><img src="__SKIN__/images/null-data.png"></div>
                </div>
            </div>
        </div>
        {else/}
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%;">
                    <thead>
                        <tr>
                            <!-- <th axis="col4"> <div class="tl text-l10">会员名/会员昵称</div> </th> -->
                            <th axis="col4"> <div class="tl text-l10">会员昵称</div> </th>
                            <th axis="col4" class="w100"> <div class="tc">分销商级别</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">分销商姓名/手机号</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">提现方式</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">申请佣金</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">申请时间</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">状态</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">操作</div> </th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%">
                    <tbody>
                        {foreach name="withdrawList" item="vo" key="k" }
                        <tr>
                            <td style="width: 100%">
                                <div class="pl10 text-l10 tl">
                                    <img id="img_head_pic" class="fl" style="width: 40px; height: 40px;" src="{$vo.head_pic|get_head_pic=###}">
                                    <!-- <p style="margin-top: -5px;"> <a href="JavaScript:void(0);" data-href="{:url('Member/users_edit', array('id'=>$vo['users_id']))}" onclick="openFullframe(this, '编辑会员', '100%', '100%');">{$vo.username}</a> </p>
                                    <p style="margin-top: -10px; color: #cccccc; font-size: 12px;"> <a href="JavaScript:void(0);" data-href="{:url('Member/users_edit', array('id'=>$vo['users_id']))}" onclick="openFullframe(this, '编辑会员', '100%', '100%');">{$vo.nickname}</a> </p> -->
                                    <p style="color: #cccccc; font-size: 12px;"> <a href="JavaScript:void(0);" data-href="{:url('Member/users_edit', array('id'=>$vo['users_id']))}" onclick="openFullframe(this, '编辑会员', '100%', '100%');">{$vo.nickname}</a> </p>
                                </div>
                            </td>

                            <td align="center">
                                <div class="w100 tc">
                                    {if condition='$vo.parent_dealer_id eq 0'}一级分销商{else/}二级分销商{/if}
                                </div>
                            </td>

                            <td> 
                                <div class="w160 tc"> 
                                <p style="margin-top: -5px;">{$vo.dealer_name}</p> 
                                <p style="margin-top: -10px;">{$vo.dealer_mobile}</p>
                                </div> 
                            </td>

                            <td> <div class="w160 tc"> {$vo.withdraw_type_name} </div> </td>

                            <td> <div class="w160 tc"> {$vo.withdraw_money} </div> </td>

                            <td> <div class="w160 tc"> {$vo.add_time|MyDate='Y-m-d H:i:s',###} </div> </td>

                            <td>
                                <div class="w160 tc">
                                    {$vo.review_status_name}<br/>
                                    <!-- {eq name='$vo.review_status' value='3'}
                                    <a href="JavaScript:void(0);" onclick="browseReason('{$vo.review_reason}');" style="color: red;"> [查看原因]</a>
                                    {/eq} -->
                                </div>
                            </td>

                            <td class="operation">
                                <div class="w160 tc">
                                    <a class="btn red" href="JavaScript:void(0);" {eq name="$vo.review_status" value="1"} data-id="{$vo.withdraw_id}" onclick="agreeApply(this);" {else/} style="color: #ccc; pointer-events: none;" {/eq}>同意</a>
                                    <i></i>
                                    <a class="btn red" href="JavaScript:void(0);" {eq name="$vo.review_status" value="1"} data-id="{$vo.withdraw_id}" onclick="refuseApply(this);" {else/} style="color: #ccc; pointer-events: none;" {/eq}>拒绝</a>
                                    <i></i>
                                    <a class="btn red" href="JavaScript:void(0);" {eq name="$vo.review_status" value="2"} data-id="{$vo.withdraw_id}" onclick="confirmPayment(this);" {else/} style="color: #ccc; pointer-events: none;" {/eq}>打款</a>
                                </div>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        {/empty}
        <div class="footer-oper">
            {$page}
            <div style="clear:both"></div>
        </div>
	</div>
</div>

<script type="text/javascript">
	layui.use('laydate', function() {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#add_time_begin' //指定元素
        });
        laydate.render({
            elem: '#add_time_end' //指定元素
        });
    });

    // 同意申请
    var reviewStatus = 1;
    function agreeApply(obj) {
        layer.confirm('请确认是否同意提现申请，请谨慎操作，不可恢复！', {
            shade: layer_shade,
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确定','取消'], //按钮
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            // 确认打款
            reviewStatus = 2;
            reviewSubmit($(obj).data('id'));
        }, function(index) {
            layer.closeAll(index);
        });
    }

    // 拒绝申请
    function refuseApply(obj) {
        layer.prompt({
            formType: 2,
            shade: layer_shade,
            value: '',
            title: '提示',
            closeBtn: 3,
            id: 'withdrawApply',
            btnAlign:'r',
            btn: ['提交', '取消'],
            area: ['300px', '100px'],
            success: function(layero) {
                $("#withdrawApply textarea").focus().attr('placeholder', '请填写拒绝原因...');
            }
        }, function(value, index) {
            reviewStatus = 3;
            reviewSubmit($(obj).data('id'), value);
            layer.close(index);
        });
    }

    // 确认已打款给分销商
    function confirmPayment(obj) {
        layer.confirm('请确认是否打款给分销商，请谨慎操作，不可恢复！', {
            shade: layer_shade,
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确定','取消'], //按钮
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            // 确认打款
            reviewStatus = 4;
            reviewSubmit($(obj).data('id'));
        }, function(index) {
            layer.closeAll(index);
        });
    }

    // 审核操作提交
    function reviewSubmit(withdrawID, reviewReason) {
        layer_loading('正在处理');
        $.ajax({
            url : "{:weapp_url('DealerPlugin/DealerPlugin/dealer_withdraw_review')}",
            type: 'post',
            data: {withdraw_id: withdrawID, review_status: reviewStatus, review_reason: reviewReason, _ajax: 1},
            dataType: 'json',
            success: function(res) {
                layer.closeAll();
                if (1 == res.code) {
                    layer.msg(res.msg, {time: 1500, icon: 1}, function() {
                        window.location.reload();
                    });
                } else {
                    layer.alert(res.msg, {icon: 2, title: false, closeBtn: 0});
                }
            }
        });
    }

    // 以下JS暂时停用
    function reviewPrompt(obj) {
        reviewStatus = 2;
        layer.prompt({
            formType: 2,
            shade: layer_shade,
            value: '已核实，同意提现申请',
            title: '提示',
            closeBtn: 3,
            id: 'withdrawApply',
            btnAlign:'r',
            btn: ['审核', '取消'],
            area: ['300px', '100px'],
            success: function(layero) {
                // 审核切换 radio
                var htmlCode = '<div><dd style="font-size: 14px; display: inline-block;"><label><input type="radio" name="review" value="2" onclick="reviewRadio(2);" checked="checked">&nbsp;同意</label>&nbsp; &nbsp; &nbsp;<label><input type="radio" name="review" value="3" onclick="reviewRadio(3);">&nbsp;拒绝</label<dl/><div/> <br/>';
                $("#withdrawApply").prepend(htmlCode);
            }
        }, function(value, index) {
            var withdraw_id = $(obj).data('id');
            reviewSubmit(withdraw_id, value);
            layer.close(index);
        });
    }

    function reviewRadio(review_status) {
        reviewStatus = review_status;
        if (2 == review_status) {
            $("#withdrawApply textarea").focus().html('已核实，同意提现申请');
        } else if (3 == review_status) {
            $("#withdrawApply textarea").focus().html('').attr('placeholder', '请填写拒绝原因...');
        }
    }

    // 查询拒绝原因
    function browseReason(layer_str) {
        layer.confirm(layer_str, {
            shade: layer_shade,
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['关闭'],
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            layer.closeAll();
        });
    }

    // 提现申请查询
    $(document).keydown(function(event) {
        if (event.keyCode == 13) {
            $('#searchForm input[type=text]').each(function(index, item) {
                if ($(item).is(':focus')) withdrawQuery();
            });
        }
    });

    function withdrawQuery(obj) {
        var url = $(obj).data('url') ? $(obj).data('url') : '';
        if (url) {
            window.location.href = url;
        } else {
            $('#searchForm').submit();
        }
    }
</script>

{include file="footer.htm" /}